<template>
  <div v-loading="tableLoading">
    <!-- 筛选项 -->
    <el-row :gutter="20" class="gl_searchBox" style="margin: 0 0 15px 0;">
      <el-col :span="6" :lg="4">
        <p>赛事类型</p>
        <el-select v-model="api_GET_CompetitionQO.TypeCode" size="mini" placeholder="请选择赛事类型" filterable clearable @change="getPageList()">
          <el-option v-for="item in dictAll.competitionType" :key="item.code" :value="item.code" :label="item.value" />
        </el-select>
      </el-col>
      <el-col :span="12" :lg="8">
        <p>赛事时间</p>
        <el-date-picker
          v-model="filterGameDate"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 100%;"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          size="mini"
          @change="handleGameTimeChange"
        />
      </el-col>
      <el-col :span="12" :lg="8">
        <p>赛事名称</p>
        <el-input v-model="api_GET_CompetitionQO.Filter" placeholder="请输入名称" size="mini" clearable @change="getPageList()" />
      </el-col>
      <el-col :span="6" :lg="4" class="search_btn">
        <!-- 查询按钮 -->
        <el-button type="primary" size="mini" @click="getPageList()">{{ $t('button.query') }}</el-button>
        <!-- 重置按钮 -->
        <el-button type="warning" size="mini" @click="initForm()">{{ $t('button.Reset') }}</el-button>
      </el-col>
    </el-row>

    <el-table class="gl_mb_15 game_table_list" :data="tableData" stripe size="mini" style="width: 100%">
      <el-table-column label="赛事logo" align="center" :width="95">
        <template slot-scope="{ row }">
          <img class="game_coverimg" :src="getStaticPhotoUrl(row.logoImage)" alt="" @error="errorPhoto">
        </template>
      </el-table-column>
      <el-table-column label="赛事名称" :width="250">
        <template slot-scope="{ row }">
          {{ row.parent ? row.parent.name + ' - ' + row.name : row.name }}
        </template>
      </el-table-column>
      <el-table-column label="赛事地址" :min-width="200">
        <template slot-scope="{ row }">
          {{ row.address === 'address' ? '' : row.address }}
        </template>
      </el-table-column>
      <el-table-column label="报名时间" align="center" :width="170">
        <template slot-scope="{ row }">
          {{ row.entryStartTime && row.entryStartTime.substring(0, 10) }} 到 {{ row.entryEndTime && row.entryEndTime.substring(0, 10) }}
        </template>
      </el-table-column>
      <el-table-column label="赛事时间" align="center" :width="170">
        <template slot-scope="{ row }">
          {{ row.startTime && row.startTime.substring(0, 10) }} 到 {{ row.endTime && row.endTime.substring(0, 10) }}
        </template>
      </el-table-column>
      <el-table-column prop="type.name" align="center" label="比赛类型" :width="90" />
      <el-table-column fixed="right" :label="$t('table.actions')" align="left" :width="150">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="enterToApproveDetail(row)">
            <span class="gl_color_primary">查看详情</span>
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-row style="text-align: center;" class="gl_pb_15">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        :page-size="api_GET_CompetitionQO.MaxResultCount"
        :current-page="api_GET_CompetitionQO.Page"
        @size-change="changePageSize"
        @current-change="changePage"
      />
    </el-row>
  </div>
</template>
<script>
import { mapState, mapActions } from 'vuex';
import defaultGameLogo from '@/assets/images/game/game_logoDefaultPhoto.png';
import { Api_GET_CompetitionQO } from '@/lib/form/events';
import {
  api_GET_EventsManagementCompetitionEditableList
} from '@/extend/api/gameswaggerApi/app';
export default {
  data() {
    return {
      defaultGameLogo: defaultGameLogo,
      api_GET_CompetitionQO: new Api_GET_CompetitionQO(),
      tableData: [],
      filterGameDate: [],
      total: 0,
      tableLoading: false
    };
  },
  computed: {
    ...mapState({
      dict: state => state.dict.dict,
      dictAll: state => state.dict.dictAll
    })
  },
  created() {
    this.getDict();
    this.initForm();
  },
  methods: {
    ...mapActions({ getDict: 'dict/getDict' }),
    // 初始化
    initForm() {
      this.api_GET_CompetitionQO = new Api_GET_CompetitionQO();
      this.api_GET_CompetitionQO.IncludeEntryFields = true;
      this.filterGameDate = [];
      this.getPageList();
    },
    // 获取赛事列表
    getPageList(page) {
      this.api_GET_CompetitionQO.Page = page || 1;
      this.api_GET_CompetitionQO.SkipCount = (this.api_GET_CompetitionQO.Page - 1) * this.api_GET_CompetitionQO.MaxResultCount;
      this.api_GET_CompetitionQO.HasParent = null;
      this.tableLoading = true;
      api_GET_EventsManagementCompetitionEditableList(this.api_GET_CompetitionQO).then(res => {
        this.tableLoading = false;
        this.tableData = res.items || [];
        this.total = res.totalCount;
      }, () => {
        this.tableLoading = false;
        this.$message({ type: 'error', message: '获取赛事列表失败！' });
      });
    },
    // 处理时间筛选项
    handleGameTimeChange(time) {
      this.api_GET_CompetitionQO.StartTime = time && time[0];
      this.api_GET_CompetitionQO.EndTime = time && time[1];
      this.getPageList();
    },
    // 进入赛事审核详情
    enterToApproveDetail(gameInfo) {
      this.$router.push({
        name: 'SeqApproveDetail',
        params: gameInfo
      });
    },
    // 获取图片地址
    getStaticPhotoUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultGameLogo;
    },
    changePage(page) {
      this.getPageList(page);
    },
    changePageSize(pagesize) {
      this.api_GET_CompetitionQO.MaxResultCount = pagesize;
      this.getPageList();
    }
  }
};
</script>
<style>
.game_table_list .game_coverimg {
  max-width: 74px;
  max-height: 74px;
  border-radius: 50%;
}
</style>
